package sequencing;

import anim.Matrix3D;
import dae.Node;
import dae.library.VisualScene;

import java.util.ArrayList;
import java.util.List;

public class GameObject implements Comparable<GameObject>
{
    public String id;
    public String name;
    public String type;
    public List<GameObject> children = new ArrayList<>();
    public int level;
    public GameObject parent = null;
    public Matrix3D pos;

    public GameObject(VisualScene visual_scene)
    {
        name = visual_scene.id;
        for (Node node : visual_scene.node)
        {
            GameObject gameObject = new GameObject(node, 0);
            children.add(gameObject);
        }
    }

    public GameObject(Node root, int level)
    {
        this.name = root.name;
        this.id = root.id;
        this.type = root.type;
        this.level = level;
        if (root.matrix != null)
        {
            this.pos = new Matrix3D(root.matrix);
        }
        if (root.node != null)
        {
            for (Node childNode : root.node)
            {
                GameObject child = new GameObject(childNode, level + 1);
                child.parent = this;
                children.add(child);
            }
        }

    }

    @Override
    public String toString()
    {
        return level + "," + name + "," + "parent:" + (parent == null ? "root" : parent.name);
    }

    @Override
    public int compareTo(GameObject o)
    {
        if (this.level == o.level)
        {
            if (this.name.equals(o.name))
            {
                return this.hashCode();
            }
            else
            {
                return this.name.compareTo(o.name);
            }
        }
        else
        {
            return this.level - o.level;
        }
    }

}
